'''
Created on Nov 26, 2010

@author: philip
'''

from django.http import HttpResponse
from django.utils import simplejson
from models import Link
from link_service import LinkService, AddLinkRequest
from django.template.loader import render_to_string

def add(request):
    r = request.REQUEST
    link = LinkService().addLink(AddLinkRequest(r["title"], r["url"], r["community"]))
    return HttpResponse(simplejson.dumps({"link":link,"html":render_to_string("links/links_renderer.html",{"link":link})},default=Link.toJSON),mimetype="application/json")